package org.demo.patten.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuj
 * @date 2025/3/29
 * @apiNote
 */
public class ChatRoom implements ChatRoomMediator{
    private List<User> users = new ArrayList<>();
    public void registerUser(User user) {
        users.add(user);
    }
    @Override
    public void sendMessage(String message, User sender) {
        for (User user : users) {
            // 不向发送者自己广播
            if (user != sender) {
                user.receive(message);
            }
        }
    }
}
